#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QLabel>
#include <QFile>
#include <QMessageBox>
#include <QString>
#include <QTextStream>
#include <QDebug>
#include <QPixmap>
#include <QTimer>
#include <guisettings.h>
#include <yaccsettings.h>
#include <QLineEdit>
#include <QProcess>
#include <QDir>
#include <QObject>
#include <QStringListIterator>
#include <SettingsDialog.h>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

public slots:
    void onInputClicked();
    void onComputeClicked();
    void onPlayClicked();
    void onPauseClicked();
    void onStopClicked();
    void showPic();
    void compute();
    void onProcessFinished(int exitcode, QProcess::ExitStatus exitstatus);
    void onYaccProcessFinished(int exitcode, QProcess::ExitStatus exitstatus);
    void readyReadStandardOutput();
    void readyReadStandardError();

private slots:
    void on_fieldcomboBox_currentIndexChanged(int index);

    void on_previousButton_clicked();

    void on_nextButton_clicked();

    void on_firstButton_clicked();

    void on_lastButton_clicked();

    void on_pushButton_clicked();

    void on_viscosityButton_clicked();

    void on_rayleighButton_clicked();

    void on_actionBeenden_triggered();

    void on_actionEigenschaften_triggered();


    void on_comboBox_currentIndexChanged(int index);

private:
    void setupStatusBar();
    void setupButtons();
    void updateStatusBar();
    void setupView();
    void readConfig();
    QPixmap scale(QPixmap image);
    void playLoop();
    QTimer* setupTimer(int i);
    QTimer* setupComputing(int i);
    void updateConfig();
    void setupFields();
    QString assertBool(QString number, QString fieldname);
    QString assertDouble(QString number, QString fieldname);
    QString assertInt(QString number, QString fieldname);
    void storeValue(QHash<QString,QString> *values, QString key,QString value, int type);
    void deleteFiles(QDir dir, QString filter);
    void setupPictureIterator();
    void setupFileIterator();

    Ui::MainWindow *ui;
    QDir startingDir;
    SettingsDialog *setup;
    std::vector<QString> computing;
    QString status;
    QLabel *statusMessageLabel;
    QString yaccDir;
    QString yaccPicsDir;
    QString yaccGraphicsDir;
    int interval;
    int running_Processes;
    int threads;
    int advanced;
    QString KEY_THREADS;
    QString KEY_PATH;
    QString PICS_PATH;
    QString GRAPHICS_PATH;
    QString KEY_ADVANCED;
    bool showPicState;
    QTimer *pTimer;
    QTimer *cTimer;
    QObject *cparent;
    QProcess *processes;
    QString fileold;
    int computed;
    int finished_processes;
    bool process_finished;
    bool dontstop;
    QString KEY_INTERVAL;
    static const int VALUE_DOUBLE = 1;
    static const int VALUE_INT = 2;
    static const int VALUE_BOOL = 3;
    QHash<QString, QString> *values;
    YACCSettings *yaccSettings;
    bool paused;
    bool isRunning;
    bool firstrun;
    bool varrestart;
    bool yaccfinished;
    bool finished_fields[5];
    bool lastclicked;
    int numberofPics;
    int numberofPicsOld;
    int currentPic;
    int numberofFiles;
    int numberofCheckFiles;
    int numberofcurrentFiles;
    int zaehler;
    QStringListIterator *picIter;
    QStringListIterator *checkIter;
    QString previousDisplayedPic;
    QStringListIterator *fileIter;

    QString Z_POINTS;
    QString X_POINTS;
    QString ASPECT_RATIO;
    QString TIME_STEPS_MAX;
    QString OUTPUT_STEP;
    QString RAYLEIGH;
    QString RAYLEIGH_H;
    QString VISC_CONTRAST_T;
    QString T_REF;
    QString VISC_CONTRAST_Z;
    QString Z_REF;
    QString RESTART;
};

#endif // MAINWINDOW_H
